package com.cash.loan.modular.cash.service.impl;

import com.cash.loan.common.upload.QiniuService;
import com.cash.loan.modular.cash.dao.CashVersionMapper;
import com.cash.loan.modular.cash.service.VersionService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Administrator
 * @Date 2018-10-09 9:07
 */
@Service
public class VersionServiceImpl implements VersionService {

    @Autowired
    private CashVersionMapper versionMapper;

    @Autowired
    private QiniuService qiniuService;

    @Override
    public Map<String, Object> check(String version) {
        Map<String,Object> result = new HashMap<>(4);
        String newestVersion = versionMapper.newestVersion();
        if(version.equals(newestVersion) || StringUtils.isBlank(newestVersion)) {
            result.put("isNewest",true);
            result.put("newestVersion",new HashMap<>(2));
            return result;
        } else {
            Map<String,String> versionData = versionMapper.getNewestVersionData(newestVersion);
            versionData.put("apkPath",qiniuService.getUrl(versionData.get("apkPath")));
            result.put("isNewest",false);
            result.put("newestVersion",versionData);
            return result;
        }
    }
}
